home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_dev.lha / GMSDev / Source / C / Blitter / FlipWorm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-16  |  4.5 KB  |  187 lines

  1. /* Dice: 1> dcc -l0 -mD dpk.o tags.o FlipWorm.c -o FlipWorm
  2. **
  3. ** This modified version of RamboWorm will flip the background before
  4. ** running (see FlipHBitmap()).
  5. */
  6.  
  7. #include <proto/dpkernel.h>
  8.  
  9. BYTE *ProgName      = "Flip Worm";
  10. BYTE *ProgAuthor    = "Paul Manias";
  11. BYTE *ProgDate      = "July 1998";
  12. BYTE *ProgCopyright = "DreamWorld Productions (c) 1996-1998.  Freely distributable.";
  13. BYTE *ProgShort     = "Bitmap flip demonstration.";
  14.  
  15. struct GScreen  *screen;
  16. struct Restore  *restore;
  17. struct Bob      *Worm;
  18. struct JoyData  *joydata;
  19. struct Picture  *background;
  20. struct FileName BackFile = { ID_FILENAME, "GMS:demos/data/PIC.Green" };
  21. struct FileName bobfile  = { ID_FILENAME, "GMS:demos/data/PIC.Rambo" };
  22.  
  23. WORD WormFrames[] = {
  24.     0,0,  32,0, 64,0,  96,0, 128,0, 160,0, 192,0, 224,0,
  25.   256,0, 288,0, 0,48, 32,48, 64,48,
  26.   -1,-1
  27. };
  28.  
  29. void Demo(void);
  30. void Wrap(struct Bob *);
  31.  
  32. /***************************************************************************/
  33.  
  34. void main(void) {
  35.   if (background = Load(&BackFile, ID_PICTURE)) {
  36.    if (screen = Get(ID_SCREEN)) {
  37.       CopyStructure(background, screen);
  38.       screen->Attrib = SCR_DBLBUFFER;
  39.  
  40.     if (Init(screen,NULL)) {
  41.        FlipHBitmap(background->Bitmap);
  42.  
  43.      if (Copy(background->Bitmap,screen->Bitmap) IS ERR_OK) {
  44.         CopyBuffer(screen,BUFFER2,BUFFER1);
  45.  
  46.       if (restore = InitTags(screen,
  47.            TAGS_RESTORE, NULL,
  48.            RSA_Entries,  1,
  49.            TAGEND)) {
  50.  
  51.        if (Worm = InitTags(screen,
  52.            TAGS_BOB,      NULL,
  53.            BBA_GfxCoords, WormFrames,
  54.            BBA_Width,     32,
  55.            BBA_Height,    24,
  56.            BBA_XCoord,    150,
  57.            BBA_YCoord,    150,
  58.            BBA_Attrib,    BBF_RESTORE|BBF_GENMASKS|BBF_CLIP,
  59.              BBA_SourceTags, ID_PICTURE,
  60.              PCA_Source,     &bobfile,
  61.                PCA_BitmapTags, NULL,
  62.                BMA_MemType,    MEM_BLIT,
  63.                TAGEND, NULL,
  64.              TAGEND, NULL,
  65.            TAGEND)) {
  66.  
  67.         if (joydata = Get(ID_JOYDATA)) {
  68.            joydata->Port = 1;     /* Forces mouse control */
  69.  
  70.          if (Init(joydata, NULL)) {
  71.             Display(screen); 
  72.             Demo();
  73.          }
  74.         }
  75.        }
  76.       }
  77.      }
  78.     }
  79.    }
  80.   Free(joydata);
  81.   Free(Worm);
  82.   Free(restore);
  83.   Free(screen);
  84.   Free(background);
  85.   }
  86. }
  87.  
  88. /***************************************************************************/
  89.  
  90. void Demo(void)
  91. {
  92.   WORD anim = 0;
  93.   WORD fire = FALSE;
  94.   WORD x1,x2,y1,y2,ax1,ax2,ay1,ay2;
  95.  
  96.   do
  97.   {
  98.     Activate(restore); 
  99.     Draw(Worm);
  100.     WaitAVBL();
  101.     SwapBuffers(screen);
  102.  
  103.     /* Animate the Worm's movements */
  104.  
  105.     anim++;
  106.  
  107.     if (fire IS FALSE) {
  108.       if (anim > 5) {
  109.         anim = 0;
  110.         Worm->Frame++;
  111.         if (Worm->Frame > 9)
  112.            Worm->Frame = 0;
  113.       }
  114.     }
  115.     else if (anim > 1) {
  116.       anim = 0;
  117.       if (Worm->Frame < 10)
  118.          Worm->Frame = 9;
  119.  
  120.       Worm->Frame++;
  121.  
  122.       if (Worm->Frame > 12) {
  123.          if (joydata->Buttons & JD_LMB)
  124.             Worm->Frame = 11;
  125.          else {
  126.             Worm->Frame = 0;
  127.             fire = FALSE;
  128.          }
  129.       }
  130.     }
  131.  
  132.     /* Get the user input, wrap the bob around if out of bounds */
  133.  
  134.     Query(joydata);
  135.     Worm->XCoord += joydata->XChange;
  136.     Worm->YCoord += joydata->YChange;
  137.     Wrap(Worm);
  138.  
  139.     if (joydata->Buttons & JD_LMB) {
  140.        fire = TRUE;
  141.     }
  142.  
  143.   } while (!(joydata->Buttons & JD_RMB));
  144.  
  145.   /* Randomly perform a screen wipe effect before
  146.   ** exiting the demo.
  147.   */
  148.  
  149.   if (FastRandom(5) IS 4) {
  150.      Lock(screen);
  151.      screen->Bitmap->Data = screen->MemPtr1;
  152.  
  153.      ax1 = x1 = (screen->Width - screen->Height)/2;
  154.      ay1 = y1 = NULL;
  155.  
  156.      ax2 = x2 = screen->Width - ((screen->Width - screen->Height)/2);
  157.      ay2 = y2 = screen->Height;
  158.  
  159.      while (x1 < screen->Width) {
  160.         DrawLine(screen->Bitmap,x1++,y1,x2,y2,0,0xffffffff);   /* Up/Right */
  161.         DrawLine(screen->Bitmap,ax1,ay1,ax2--,ay2,0,0xffffffff); /* Down/Left */
  162.         if (ax1 > 0) ax1--; else { ay1++; }
  163.         if (x2 < screen->Width) x2++; else y2--;
  164.         WaitAVBL();
  165.      }
  166.  
  167.      Unlock(screen);
  168.   }
  169. }
  170.  
  171. /*****************************************************************************
  172. ** Function: This function will wrap a bob to the other side of a screen if
  173. **           it leaves the bob's screen borders.
  174. **
  175. ** Synopsis: Wrap(Bob);
  176. */
  177.  
  178. void Wrap(struct Bob *bob)
  179. {
  180.   if (bob->XCoord < -bob->Width)  bob->XCoord = bob->DestBitmap->Width;
  181.   if (bob->YCoord < -bob->Height) bob->YCoord = bob->DestBitmap->Height;
  182.  
  183.   if (bob->XCoord > bob->DestBitmap->Width)  bob->XCoord = -bob->Width;
  184.   if (bob->YCoord > bob->DestBitmap->Height) bob->YCoord = -bob->Height;
  185. }
  186.  
  187.